// 日期格式化
function formatDate(dateStr) {
    if (!dateStr) return '';
    return dateStr.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
}

function formatDateToNumber(dateStr) {
    if (!dateStr) return '';
    return dateStr.replace(/-/g, '');
}

//股票代码添加后缀
function addSuffix(code) {
    if (!code) return "";
    if (code.startsWith("6")) return code + ".SH";
    else if (code.startsWith("0") || code.startsWith("3")) return code + ".SZ";
    else return code;
}

// 获取最近10条数据
function getRecent10Data(data) {
    if (data.length <= 10) {
        return data;
    }
    return data.slice(-10);
}

// HEX颜色转RGBA
function hexToRgba(hex, alpha) {
    const r = parseInt(hex.slice(1, 3), 16);
    const g = parseInt(hex.slice(3, 5), 16);
    const b = parseInt(hex.slice(5, 7), 16);

    return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}